package blackhouse.laobi.collection.day15;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class GenericDemo7 {

	public static void main(String[] args) {
		TreeSet<Student7> ts = new TreeSet<Student7>(new Comp());
		ts.add(new Student7("abc1"));
		ts.add(new Student7("abc2"));
		ts.add(new Student7("abc3"));
		Iterator<Student7> it = ts.iterator();
		while (it.hasNext()) {
			System.out.println(it.next().getName());
		}
		TreeSet<Worker7> ts1 = new TreeSet<Worker7>(new Comp());
		ts1.add(new Worker7("wabc1..."));
		ts1.add(new Worker7("wabc2..."));
		ts1.add(new Worker7("wabc3...."));
		Iterator<Worker7> it1 = ts1.iterator();
		while (it1.hasNext()) {
			System.out.println(it1.next().getName());
		}
	}

}

/*
 * class StuComp implements Comparator<Student7> {
 * 
 * @Override public int compare(Student7 s1, Student7 s2) {
 * 
 * return s1.getName().compareTo(s2.getName()); }
 * 
 * } class WorkerComp implements Comparator<Worker7> {
 * 
 * @Override public int compare(Worker7 s1, Worker7 s2) {
 * 
 * return s1.getName().compareTo(s2.getName()); }
 * 
 * }
 */
class Comp implements Comparator<Person> {

	@Override
	public int compare(Person o1, Person o2) {

		return o1.getName().compareTo(o2.getName());
	}
}

class Person7 {
	private String name;

	Person7(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	@Override
	public String toString() {
		return "Person:" + name;
	}
}

class Student7 extends Person {
	Student7(String name) {
		super(name);
	}
}

class Worker7 extends Person {
	Worker7(String name) {
		super(name);
	}
}